#include "MouseSubject.h"


MouseSubject::MouseSubject(void)
{
}


MouseSubject::~MouseSubject(void)
{
}

void MouseSubject::AddMouseListener( MouseListener *listener )
{
	mouseListeners.insert(listener);
}

void MouseSubject::DeleteMouseListener( MouseListener *listener )
{
	mouseListeners.erase(listener);
}

void MouseSubject::MouseNotify( MouseMsg msg )
{
	std::set<MouseListener*>::const_iterator iter;
	for(iter=mouseListeners.begin(); iter!=mouseListeners.end() ;++iter)
		(*iter)->MouseUpdate(msg,m_ptOldPoint,m_ptCurrPoint);
}

MouseSubject* MouseSubject::Instance()
{
	static MouseSubject* m_instance = NULL;
	if(!m_instance)
		m_instance = new MouseSubject();
	return m_instance;
}

void MouseSubject::SetCurrentPoint( int x,int y )
{
	m_ptCurrPoint.x = x;
	m_ptCurrPoint.y = y;
}

void MouseSubject::UpdateOldPoint()
{
	m_ptOldPoint = m_ptCurrPoint;
}
